package com.ipet.app.util;

import com.google.gson.Gson;

/**
 * User: sush
 * Date: 2015-08-04.
 */
public class SerializeManager {
    private static SerializeManager instance = new SerializeManager();
    private Gson gson;

    public SerializeManager() {
        gson = new Gson();
    }

    public static SerializeManager getInstance() {
        return instance;
    }

    public String serialize(Object object) {
        try {
            return gson.toJson(object);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public <T> T deserialize(String json, Class<T> tClass) {
        try {
            return gson.fromJson(json, tClass);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
